package com.game.server.message.proto.execute;

import com.comm.ISession;

import com.game.majiang.config.DataManager;
import com.game.majiang.logic.LogicClient;
import com.game.majiang.logic.LogicServer;
import com.game.server.db.dao.XyClubMemberInfoDao;
import com.game.server.db.entity.XyClubInfo;
import com.game.server.db.entity.XyClubMemberInfo;
import com.game.server.message.proto.in.AbstractXYLeaveTheClubReq;
import com.game.server.message.proto.out.XYInformDataAlterRsp;
import com.game.server.message.proto.out.XYLeaveTheClubRsp;

public class XYLeaveTheClubReq extends AbstractXYLeaveTheClubReq {

    @Override
    public void Execute(ISession session) {
        LogicClient client = (LogicClient) LogicServer.getInstance().getClient(session.getId());
        if (client != null&&client.checkClick(msgcode)) {
            XYLeaveTheClubRsp rsp = new XYLeaveTheClubRsp();
            rsp.setIsok(1);
            rsp.setClubid(this.clubid);
            XyClubInfo clubInfo = DataManager.getInstance().getMapClub().get(this.clubid);
            if (clubInfo!=null){
                XyClubMemberInfo clubMemberInfo = clubInfo.getPlayer().get(client.getUserId());
                if (clubMemberInfo!=null && clubMemberInfo.getIsManager()!=1){
                    int deleteClubMember = XyClubMemberInfoDao.deleteClubMember(clubMemberInfo.getId(), 1);
                    if (deleteClubMember>0){
                        rsp.setIsok(0);
                        clubMemberInfo.setDel_type(1);
                        DataManager.getInstance().getMapUserData().get(client.getUserId()).getClubids().remove(Integer.valueOf(clubInfo.getId()));
                        //通知
                        XYInformDataAlterRsp alterRsp = new XYInformDataAlterRsp();
                        alterRsp.setType(4);
                        alterRsp.setOperateclubid(this.clubid);
                        alterRsp.setClubid(this.clubid);
                        alterRsp.setUnionid(clubMemberInfo.getUid());
                        clubInfo.broadCastAdminPlayer(alterRsp);
                    }
                }
            }
            client.Send(rsp);
        }
    }
}
